<?php defined('IN_IA') or exit('Access Denied');?><?php (!empty($this) && $this instanceof WeModuleSite || 1) ? (include $this->template('common/header', TEMPLATE_INCLUDEPATH)) : (include template('common/header', TEMPLATE_INCLUDEPATH));?>
<ul class="nav nav-tabs">
    <li <?php  if($op=='list' ) { ?> class="active" <?php  } ?>>
        <a href="<?php  echo $this->createWebUrl('pid', array('op' => 'list'));?>">推广位PID列表</a>
    </li>
    <li <?php  if($op=='add' ) { ?> class="active" <?php  } ?>>
        <a href="<?php  echo $this->createWebUrl('pid', array('op' => 'add'));?>">推广位PID导入（检查更新）</a>
    </li>
	<li <?php  if($op=='add2' ) { ?> class="active" <?php  } ?>>
        <a href="<?php  echo $this->createWebUrl('pid', array('op' => 'add2'));?>">推广位PID导入（不检查更新直接导入）</a>
    </li>
	<li style="background-color:red;color:#FFFFFF;"><a href="<?php  echo $this->createWebUrl('pid', array('op' => 'delall'));?>" onclick="return confirm('确认删除全部PID吗？请谨慎操作！');return false;">删除全部PID</a></li>
</ul>

<?php  if($op=='add' ) { ?>
<div class="panel panel-default">
  <div class="panel-heading">导入推广位PID</div>
  <div class="panel-body">
    <div class="alert alert-info" role="alert">
        默认导入格式请下载模板格式。
        <p>(<a href="<?php echo MODULE_URL;?>template/upfile/pid.xlsx" target="_blank" style="font-size:16px;color:red">点击下载上传模板</a>)</p>
    </div>
    <form class="form-horizontal" action="" method="post" enctype="multipart/form-data" onsubmit="return check(this);" >
      
      <div class="form-group">
        <label for="" class="col-sm-2 col-sm-1 control-label">推广位PIDexcel文件</label>
        <div class="col-sm-4 col-xs-12">
          <input type="file" name="pid" class="form-control" id="pid">
        </div>
      </div>
      <div class="form-group">
            <label for="" class="col-sm-2 col-sm-1 control-label"></label>
            <div class="col-sm-10 col-xs-12">
                <button type="button" id="myButton" data-loading-text="正在导入中，请勿关闭和刷新浏览器......" class="btn btn-primary" autocomplete="off">
                    提交
                </button>
                <input type="hidden" name="token" value="<?php  echo $_W['token'];?>" />
            </div>
      </div>
    </form>
  </div>
</div>

<script type="text/javascript">
  function check(form){
            if (!form['pid'].value) {
                alert('请上传推广位PID表格');
                return false;
            }
            return true;
        }
</script>
<script>
    $('#myButton').on('click', function () {
        var $btn = $(this).button('loading');
        var formData = new FormData();
        formData.append('pid', $('#pid')[0].files[0]);
        $.ajax({
            url : "<?php  echo $this->createWebUrl('pid',array('op'=> 'add'))?>",
            type : "POST",
            cache: false,
            data : formData,
            processData: false,
            contentType: false,
            dataType: "json",
            success : function(data) {
                if(data.result){
                    alert(data.content);
                    setTimeout(function(){
                        window.location.href="<?php  echo $this->createWebUrl('pid')?>";
                    },000);
                }else{
					alert(data.content);
				}
            },
            error : function(data) {

            }
        });
    })
</script>
<?php  } else if($op=='add2') { ?>
<div class="panel panel-default">
  <div class="panel-heading">导入推广位PID（不检查更新直接导入）</div>
  <div class="panel-body">
    <div class="alert alert-info" role="alert">
        默认导入格式请下载模板格式。
        <p>(<a href="<?php echo MODULE_URL;?>template/upfile/pid.xlsx" target="_blank" style="font-size:16px;color:red">点击下载上传模板</a>)</p>
    </div>
    <form class="form-horizontal" action="" method="post" enctype="multipart/form-data" onsubmit="return check(this);" >
      
      <div class="form-group">
        <label for="" class="col-sm-2 col-sm-1 control-label">推广位PIDexcel文件</label>
        <div class="col-sm-4 col-xs-12">
          <input type="file" name="pid" class="form-control" id="pid">
        </div>
      </div>
      <div class="form-group">
            <label for="" class="col-sm-2 col-sm-1 control-label"></label>
            <div class="col-sm-10 col-xs-12">
                <button type="button" id="myButton" data-loading-text="正在导入中，请勿关闭和刷新浏览器......" class="btn btn-primary" autocomplete="off">
                    提交
                </button>
                <input type="hidden" name="token" value="<?php  echo $_W['token'];?>" />
            </div>
      </div>
    </form>
  </div>
</div>

<script type="text/javascript">
  function check(form){
            if (!form['pid'].value) {
                alert('请上传推广位PID表格');
                return false;
            }
            return true;
        }
</script>
<script>
    $('#myButton').on('click', function () {
        var $btn = $(this).button('loading');
        var formData = new FormData();
        formData.append('pid', $('#pid')[0].files[0]);
        $.ajax({
            url : "<?php  echo $this->createWebUrl('pid',array('op'=> 'add2'))?>",
            type : "POST",
            cache: false,
            data : formData,
            processData: false,
            contentType: false,
            dataType: "json",
            success : function(data) {
                if(data.result){
                    alert(data.content);
                    setTimeout(function(){
                        window.location.href="<?php  echo $this->createWebUrl('pid')?>";
                    },000);
                }else{
					alert(data.content);
				}
            },
            error : function(data) {

            }
        });
    })
</script>
<?php  } else if($op=='list') { ?>
<div class="panel panel-info">
		<div class="panel-heading">筛选</div>
		<div class="panel-body">
			<form action="./index.php" method="get" class="form-horizontal" role="form" id="form1">
				<input type="hidden" name="c" value="site" />
				<input type="hidden" name="a" value="entry" />
				<input type="hidden" name="m" value="<?php  echo $this->modulename?>" />
				<input type="hidden" name="do" value="pid" />
				

				<div class="form-group">
					<label class="col-xs-12 col-sm-1 control-label">PID搜索</label>
					<div class="col-sm-2 col-xs-12">
						<input class="form-control" name="keyword1" id="" type="text" value="<?php  echo $_GPC['keyword1'];?>" placeholder="根据PID搜索">
					</div>
					<label class="col-xs-12 col-sm-1 control-label">用户昵称搜索</label>
					<div class="col-sm-2 col-xs-12">
						<input class="form-control" name="keyword2" id="" type="text" value="<?php  echo $_GPC['keyword2'];?>" placeholder="根据用户昵称号搜索">
					</div>
					<div class="col-sm-5">
						<button class="btn btn-default"><i class="fa fa-search"></i> 搜索</button>
						<button type="button" class="btn btn-default">总记录数：<?php  echo $total;?></button>
						<button type="button" class="btn btn-default">已使用：<?php  echo $usetotal;?></button>
						<button type="button" class="btn btn-default">未使用：<?php  echo $nousetotal;?></button>
					</div>
				</div>
			</form>
		</div>
</div>

<form action="" class="form-horizontal form" method="post" enctype="multipart/form-data">
    <div style="padding:15px;">
        <table class="table table-hover table-condensed">
            <thead class="navbar-inner">
                <tr>
                    <th class="col-sm-1">选择</th>
                    <th class="col-sm-1">ID</th>
					<th class="col-sm-1">推广位名称</th>
                    <th class="col-sm-1">推广位PID</th>
					<th class="col-sm-1">渠道关系ID</th>
					<th class="col-sm-1">折淘客sid</th>
					<th class="col-sm-1">会员昵称</th>
                    <th class="col-sm-1">是否使用</th>
					<th class="col-sm-1">使用时间</th>
					<th class="col-sm-1">最近使用时间</th>
					<th class="col-sm-1">删除</th>
                </tr>
            </thead>
            <tbody>
                <?php  if(is_array($list)) { foreach($list as $item) { ?>
                <tr>
                    <td style="width:30px;">
                        <input type="checkbox" name="rid[]" value="<?php  echo $item['id'];?>">
                    </td>
                    <td><?php  echo $item['id'];?></td>
					<td><?php  echo $item['pidname'];?></td>
					<td><?php  echo $item['pid'];?></td>
					<td><?php  echo $item['rid'];?></td>
					<td><?php  echo $item['sid'];?></td>
					<td><?php  echo $item['nickname'];?></td>
					<td><?php  if($item['is_use']==1) { ?>正在使用<?php  } else { ?>未使用<?php  } ?></td>
					<td><?php  if($item['use_time']) { ?><?php  echo date("Y-m-d H:i:s", $item['use_time']);?><?php  } ?></td>
					<td><?php  if($item['update_time']) { ?><?php  echo date("Y-m-d H:i:s", $item['update_time']);?><?php  } ?></td>
					<td>
                        <a href="<?php  echo $this->createWebUrl('pid',array('op' => 'delete','id' => $item['id']))?>" onclick="return confirm('此操作不可恢复，确认吗？'); return false;" title="删除" class="btn btn-default btn-sm"><i class="fa fa-delete" data-toggle="tooltip" data-placement="top"></i>删除</a>
                    </td>
                </tr>
                <?php  } } ?>
            </tbody>
        </table>
        <table class="table table-hover">
            <tr>
                <td width="30">
                    <input type="checkbox" onclick="var ck = this.checked;$(':checkbox').each(function(){this.checked = ck});" />
                </td>
                <td class="text-left">
                    <input name="token" type="hidden" value="<?php  echo $_W['token'];?>" />
                    <input type="submit" onclick="return confirm('此操作不可恢复，确认吗？'); return false;" class="btn btn-primary span2" name="delete" value="删除" />
                </td>
            </tr>
        </table>
        <?php  echo $pager;?>
    </div>
</form>

<?php  } ?>
<?php (!empty($this) && $this instanceof WeModuleSite || 1) ? (include $this->template('common/footer', TEMPLATE_INCLUDEPATH)) : (include template('common/footer', TEMPLATE_INCLUDEPATH));?>
